/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package eeep.controles;

import eeep.dao.ConfirmacaoDAO;
import eeep.entidades.Confirmacao;
import eeep.excecoes.CCEException;
import eeep.excecoes.CNEException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Joao
 */
public class ConfirmacaoControle {
    ConfirmacaoDAO dao=new ConfirmacaoDAO();
    
    public void cadastrarConfirmacao(Confirmacao confirmacao){
        dao.cadastrarConfirmacao(confirmacao);
    }
    public Confirmacao buscarConfirmacao(String email)throws CNEException{
        Confirmacao conf=dao.getConfirmacao(email);
        if(conf!=null){
            return conf;
        }else{
            throw new CNEException();
        }
    }
    public void confirmaCodigo(Confirmacao confirmacao)throws CCEException{
        try {
            Confirmacao aux=this.buscarConfirmacao(confirmacao.getEscola().getEmail());
            if(aux.getCod().equals(confirmacao.getCod())){
                dao.confirmaConfirmacao(confirmacao.getEscola().getEmail());
                dao.removerConfirmacao();
            }else{
                throw new CCEException();
            }
        } catch (CNEException ex) {
            Logger.getLogger(ConfirmacaoControle.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
